<?php

namespace App\Http\Controllers\Web\Member\Seller;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;

class ShopController extends BaseController
{
    protected $api_url = [
        'configure' => ['get', 'seller/configure'],
        'configure_update' => ['put', 'seller/configure/%d'],
    ];

    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_web');
    }

    public function index()
    {
        //参数部分


        //请求部分
        $ret = http_web($this->api_url['configure'])->send();

        //结果处理部分
        $data = paginate($this->request, $ret['data']);

        //回填搜索框值

//        return  $data;
        return view('web.user.seller.shop_configure', $data['list'][0]);
    }

    public function show($id)
    {

    }

    public function create(){
       return view('form', ['type' => 'create']);
    }

    public function store(){

    }

    public function edit($id)
    {
        return view('form', ['type' => 'update']);
    }

    public function update($id)
    {
        $this->validate($this->request, [
            'sp_title' => 'required'
        ]);
        $data = $this->request->all([]);

        $ret = http_web($this->api_url['configure_update'],[$id])->send($data);

        if(isset($ret['code']) && $ret['code']===0 ){
            return response()->json(['code'=>0,'message'=>'']);
        }else{
            return response()->json(['code'=>1,'message'=>$ret['message']]);
        }

    }

    public function destroy()
    {

    }




}